<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored ="false" %>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>

<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="btnsBox formBtns notRight">
                <span id="addTkBusBtn" class="sq-button-round" onclick="addTkBus();">新增</span>
            </div>
        </div>
    </form>
</div>
<div id="tkBusGrid" class="sq-grid"></div>
</div>
<!-- 是否显示提交按钮 -->
<sys:funcAuth resCd="PrdSubmit">
	<span id="isShowCmtBtn" />
</sys:funcAuth>
<!-- 是否显示审核按钮  启用禁用按钮 -->
<sys:funcAuth resCd="PrdCheck">
	<span id="isShowAudBtn" />
</sys:funcAuth>
<script type="text/javascript">
	var tkBusGrid;
	var callback_tkBus = function () {
        tkBusGrid.setParm("prdId",_prdId);
		tkBusGrid.reload();
    };
	$(function () {
		var _url = '<%=path%>/product/prdTkBusInfo/initList.do?';
	    tkBusGrid = $("#tkBusGrid").ligerGrid({
	    	url:_url ,
	    	method : 'get',
	        columns: [
	            { display: '产品子编码', name: 'id', width: 120 ,
	            	render: function (rowdata, rowindex, value){
						var h='<a href="javascript:showDetail_tkBus(';
						h+="'"+rowdata.id+"'";
				        h+=')">'+rowdata.id+'</a>';
				    	return h;
					}
	            },
	            { display: '驱动', name: 'drvTypCdNm', width: 120 },
	            { display: '发动机型号', name: 'engMdl', width: 120 },
	            { display: '启停状态', name: 'isValidNm', width: 80 },
	            { display: '审核状态', name: 'audStsCdNm', width: 100 },
	            getOperateColumn_tkBus()
	        ],
	        pageSize:10,
	        root:'rows',
	        parms:{prdId:_prdId},
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        checkbox:true,
	        rownumbers:true
	    });
	});
	function getOperateColumn_tkBus(){
		return { 
	        	display: '操作',minWidth: 250,align:'left',
	        	render: function (rowdata, rowindex, value){
	        		var v;
                    var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable_tkBus(';
                        v1+="'"+rowdata.id+"'";
                        v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
                        
                    var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable_tkBus(';
                        v2+="'"+rowdata.id+"'";
                        v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                	switch (rowdata.isValid){
                       case 0:
                           v=v2;
                           break;
                       case 1:
                           v=v1;
                           break;
                       default:
                       	v=v1;
                       	break;
                    }
                	var b='<a class="sq-button-hasicon" href="javascript:modifyAudStsCd_tkBus(';
		                b+="'"+rowdata.id+"'";
		                b+=",'"+FlowConstant.FLOW_CHECK_STATE_IN+"'";
		                b+=')"><i class="sqBtnIco_22"></i>提交</a>';
	    			var h='<a class="sq-button-hasicon" href="javascript:changeAudStsCd_tkBus(';
		                h+="'"+rowdata.id+"'";
		                h+=')"><i class="sqBtnIco_6"></i>审核</a>';
	        		var g='<a class="sq-button-hasicon" href="javascript:change_tkBus(';
	            		g+="'"+rowdata.id+"'";
	                    g+=')"><i class="sqBtnIco_4"></i>修改</a>';
	            	var d='<a class="sq-button-hasicon" href="javascript:deleteRecord_tkBus(';
	            		d+="'"+rowdata.id+"'";
	                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
                    var isShowCmtBtn = $("#isShowCmtBtn");
                    var isShowAudBtn = $("#isShowAudBtn");
                    var end = "";
                  	//有提交权限  && 审核状态:待提交||审核不通过 -->提交按钮显示
                    if(isShowCmtBtn.length){
                    	if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON || rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NO_PASS)
                    	end += b;
                    }
                    //有审核权限  显示启用禁用
                    if(isShowAudBtn.length){
                    	end+=v;
                    	// 有审核权限 && 审核状态!=待提交 -->审核按钮显示
                    	if(rowdata.audStsCd!=FlowConstant.FLOW_CHECK_STATE_NON){
	                    	end += h;
                    	}
                    }
                    //有提交权限 && 审核状态:待提交||审核不通过  -->修改删除显示
                    if(isShowCmtBtn.length ){
                    	if(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NON || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NO_PASS){
	                    	end += g;
	                    	end += d;
                    	}
                    }
		            return end;
	        	}
			}
	}
	function changeAudStsCd_tkBus(_id){
		if(!_id)return;
		$.ligerDialog.SQopen({
            width: 1100,
            height:500,
            title : '审核车辆信息',
            url:'<%=path%>/product/prdTkBusInfo/toAddPage.do?isShowAuditBtn=1&id='+_id+'&prdId='+_prdId+'&bizTypCd='+_bizTypCd+'&bizCd='+_bizCd+'&sGrpCd='+_sGrpCd+'&sCode='+_sCode,
            buttons: [{
		                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onOk) Dialog.onOk();
		                }
		            },{
		                text: "审核通过", type: 'ok', cls: 'l-dialog-btn-ok',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onOk) Dialog.audPass();
		                }
		            },{
		                text: "审核不通过", type: 'ok', cls: 'l-dialog-btn-ok',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onOk) Dialog.audNoPass();
		                }
		            }, {
		                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
		                onclick: function (item, Dialog) {
		                    if (Dialog.onCancel) Dialog.onCancel();
		                }
		            }
		        ]
        });
		<%-- $.ligerDialog.SQopen({
            width: 500,
            height:200,
            title : '审核信息',
            url:'<%=path%>/product/prdTkBusInfo/toModifyAudStsCdPage.do?id='+_id,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        }); --%>
	}
	function addTkBus(){
		if(_prdId==""){
    		$.ligerDialog.SQalert({content: "请先保存产品基本信息！" , SQ_type: "warning" });
	    	return;
    	}
    	$.ligerDialog.SQopen({
            width: 1110,
            height:500,
            title : '新增车辆',
            url:'<%=path%>/product/prdTkBusInfo/toAddPage.do?prdId='+_prdId+'&bizTypCd='+_bizTypCd+'&bizCd='+_bizCd+'&sGrpCd='+_sGrpCd+'&sCode='+_sCode,
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        if (Dialog.onOk) Dialog.onOk();
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
	function change_tkBus(_id){
		if(!_id)return;
		$.ligerDialog.SQopen({
            width: 1100,
            height:500,
            title : '修改车辆信息',
            url:'<%=path%>/product/prdTkBusInfo/toAddPage.do?id='+_id+'&prdId='+_prdId+'&bizTypCd='+_bizTypCd+'&bizCd='+_bizCd+'&sGrpCd='+_sGrpCd+'&sCode='+_sCode,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	function showDetail_tkBus(_id){
		if(!_id)return;
		$.ligerDialog.SQopen({
            width: 1100,
            height:500,
            title : '查看车辆信息',
            url:'<%=path%>/product/prdTkBusInfo/toDetailPage.do?id='+_id+'&prdId='+_prdId+'&bizTypCd='+_bizTypCd+'&bizCd='+_bizCd+'&sGrpCd='+_sGrpCd+'&sCode='+_sCode,
            buttons: [{
	                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        });
	}
	//删除数据
	function deleteRecord_tkBus(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/product/prdTkBusInfo/removeByIds.do',
				beforeSend: function(){
				     wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 tkBusGrid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	//提交  修改审核状态(审核中)
	function modifyAudStsCd_tkBus(_id,_audStsCd){
	    if(!_id || !_audStsCd)return;
	    var url = '<%=path%>/product/prdTkBusInfo/modifyAudStsCd.do';
	    var wait_dialog;
	    $.ajax({
			type: 'post',
			dataType:'json',
			data:{
				id:_id,
				audStsCd:_audStsCd,
				prdId:_prdId,
				isSubmit:1
			},
			url: url,
			beforeSend: function(){
		          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
		     },
			success:function(msg){
				 wait_dialog.close();
				 if(msg.success == 1){
					 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					 tkBusGrid.reload();
				 }else{
					 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				 }
			}
		});
	}
	//启用
	function enable_tkBus(id){
		if(!id)return;
   		$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/prdTkBusInfo/enable.do',
   				success:function(msg){
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 tkBusGrid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	
	function disable_tkBus(id){
		if(!id)return;
   		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/prdTkBusInfo/disable.do',
   				success:function(msg){
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 tkBusGrid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
</script>
